const mongoose = require('mongoose');

const danmuSchema = new mongoose.Schema(
  {
    duration: {
      type: Number,
      default: 15000,
    },
    style: {
      type: Object,
      default: {
        color: '#ffffff',
        fontSize: '20px',
        padding: '5px 11px',
        height: '20px',
      },
    },
    txt: {
      type: String,
      required: [true, 'danmu cannot be empty'],
      trim: true,
    },
    start: {
      type: Number,
      required: [true, 'danmu must have start'],
    },
    video: {
      type: mongoose.Schema.ObjectId,
      ref: 'Video',
      required: [true, 'danmu must belong to a Video'],
    },
    user: {
      type: mongoose.Schema.ObjectId,
      ref: 'User',
      required: [true, 'danmu must belong to a user'],
    },
  },
  {
    toJSON: { virtuals: true },
    toObject: { virtuals: true },
  }
);

const Danmu = mongoose.model('Danmu', danmuSchema);

module.exports = Danmu;
